/**
 * MineAdmin is committed to providing solutions for quickly building web applications
 * Please view the LICENSE file that was distributed with this source code,
 * For the full copyright and license information.
 * Thank you very much for using MineAdmin.
 *
 * @Author X.Mo<root@imoi.cn>
 * @Link   https://github.com/mineadmin
 */
import type { MaFormItem } from "@mineadmin/form";
import hasAuth from "@/utils/permission/hasAuth.ts";
import MaDictRadio from "@/components/ma-dict-picker/ma-dict-radio.vue";
import MaRemoteSelect from "@/components/ma-remote-select/index.vue";
import { concat } from "lodash-es";
import { getAll as getVendorsList } from "$/attractions/inspection/api/inspectionVendors.ts";
import { page as getDeviceTypesList } from "$/attractions/inspection/api/inspectionDeviceTypes.ts";

export default function getFormItems(
  formType: "add" | "edit" = "add",
  t: any,
  model: any
): MaFormItem[] {
  return concat([
    {
      label: "设备名称",
      prop: "name",
      render: "input",
      renderProps: { placeholder: t("form.pleaseInput", { msg: "设备名称" }) },
      itemProps: { rules: [{ required: true, message: "请输入设备名称" }] },
    },
    {
      label: "设备型号",
      prop: "model",
      render: "input",
      renderProps: { placeholder: t("form.pleaseInput", { msg: "设备型号" }) },
      itemProps: { rules: [{ required: true, message: "请输入设备型号" }] },
    },
    {
      label: "经度",
      prop: "longitude",
      render: "input",
      renderProps: { placeholder: t("form.pleaseInput", { msg: "经度" }) },
      itemProps: { rules: [{ required: true, message: "请输入经度" }] },
    },
    {
      label: "纬度",
      prop: "latitude",
      render: "input",
      renderProps: { placeholder: t("form.pleaseInput", { msg: "纬度" }) },
      itemProps: { rules: [{ required: true, message: "请输入纬度" }] },
    },
    {
      label: "海拔高度",
      prop: "altitude",
      render: "input",
      renderProps: { placeholder: t("form.pleaseInput", { msg: "海拔高度" }) },
      itemProps: { rules: [{ required: true, message: "请输入海拔高度" }] },
    },
    {
      label: "设备类型",
      prop: "type_id",
      render: () => MaRemoteSelect,
      renderProps: {
        api: getDeviceTypesList,
        dataHandle: (response: any) => {
          if (response.code === 200 && response.data && response.data.list) {
            return response.data.list.map((item: any) => ({
              label: item.name || `设备类型${item.id}`,
              value: item.id,
            }));
          }
          return [];
        },
        placeholder: "请选择设备类型",
        clearable: true,
        multiple: false,
      },
      itemProps: { rules: [{ required: true, message: "请选择设备类型" }] },
    },
    {
      label: "当前状态",
      prop: "status",
      render: () => MaDictRadio,
      renderProps: {
        data: [
          { label: "在线", value: 1 },
          { label: "离线", value: 2 },
        ],
        placeholder: "请选择设备状态",
      },
      itemProps: {
        rules: [{ required: true, message: "请选择设备状态" }],
      },
    },
    {
      label: "供应商",
      prop: "vendor_id",
      render: () => MaRemoteSelect,
      renderProps: {
        api: getVendorsList,
        dataHandle: (response: any) => {
          if (
            response.code === 200 &&
            response.data &&
            response.data.list
          ) {
            return response.data.list.map((item: any) => ({
              label: item.name || `供应商${item.id}`,
              value: item.id,
            }));
          }
          return [];
        },
        placeholder: "请选择供应商",
        clearable: true,
        multiple: false,
      },
      itemProps: { rules: [{ required: true, message: "请选择供应商" }] },
    },
    {
      label: "服务商",
      prop: "service_id",
      render: () => MaRemoteSelect,
      renderProps: {
        api: getVendorsList,
        dataHandle: (response: any) => {
          if (
            response.code === 200 &&
            response.data &&
            response.data.list
          ) {
            return response.data.list.map((item: any) => ({
              label: item.name || `服务商${item.id}`,
              value: item.id,
            }));
          }
          return [];
        },
        placeholder: "请选择服务商",
        clearable: true,
        multiple: false,
      },
    },
    {
      label: "关联设备",
      prop: "device",
      render: "input",
      renderProps: { placeholder: t("form.pleaseInput", { msg: "关联设备" }) },
    },
  ]);
}
